package cn.xuchunh.exam;

import java.util.Scanner;

/**
 * Created by XuChunH on 2016/9/13.
 */
public class EvenDistance {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int length = scanner.nextInt();
        int[] array = new int[length];
        for (int i = 0; i < length; i++) {
            array[i] = scanner.nextInt();
        }
        int[] temp = new int[length - 1];
        for (int i = 0; i < length - 1; i++) {
            for (int j = array[i] + 1; j < array[i + 1]; j = j + 2) {
                if(isPrimary(j)){
                    temp[i] ++;
                }
            }
        }
        int sum = temp[0] * temp.length;
        for (int i = 1; i < temp.length; i++) {
            sum += (i + 1) * (temp.length - i) * temp[i];
        }
        System.out.println(sum);

    }

    private static boolean isPrimary(int a){
        int bound = (int) Math.sqrt(a);
        for (int i = 2; i <= bound; i++) {
            if(a % i == 0){
                return false;
            }
        }
        return true;
    }
}
